package com.bobohost.crmrbac.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bobohost.crmrbac.dao.mapper.DepartmentMapper;
import com.bobohost.crmrbac.pojo.po.Department;
import com.bobohost.crmrbac.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
//@RequiredArgsConstructor
@Transactional(readOnly = true)
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;


//    private DepartmentMapper departmentMapper;
//    @Autowired
//    public DepartmentServiceImpl(DepartmentMapper departmentMapper) {
//        this.departmentMapper = departmentMapper;
//    }

    @Override

    public List<Department> findDepartmentList() {

        return baseMapper.selectList(null);
    }

    @Override
    public Department findDepartmentById(int id) {
        return baseMapper.selectById(id);

    }

    @Override
    public void updateDepartment(Department department) {
        baseMapper.updateById(department);


    }

    @Override
    @Transactional
    public void removeById(Integer id) {
        baseMapper.deleteById(id);

    }

    @Override
    @Transactional()
    public void saveOrUpdateDepartment(Department department) {
        baseMapper.insertOrUpdate(department);


    }

    @Override
    public IPage<Department> findDepartmentListPage(IPage page) {
        List<Department> departmentList = baseMapper.selectList(null);

        IPage<Department> pageResult = baseMapper.selectPage(page, null);

        return pageResult;
    }
    @Override
    public List<Department> list() {
        return baseMapper.selectList(null);
    }

}
